from collections import defaultdict


# 邻接表
def build_graph(input_file):
    """
    input_file:
        4 5
        A B 
        B D 
        C A 
        C D 
        D B
    """
    map = defaultdict(list)

    with open(input_file) as f:
        # 跳过头部（顶点个数，边数）信息
        f.readline()

        # 顶点-> [顶点列表]
        for line in f.readlines():
            u, v = line.strip().split()
            map[u].append(v)

        return map

for k, v in build_graph("graph.txt").items():
    print(k, '----->', v)